package com.happy.xiao.common.sqlReadWrite;

import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

public class SnowflakeIdGenerator implements IdentifierGenerator {

    private static SnowflakeId snowflakeId;

    public static void setSnowflakeId(SnowflakeId snowflakeId) {
        SnowflakeIdGenerator.snowflakeId = snowflakeId;
    }

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor,
                                 Object o) throws HibernateException {
        return snowflakeId.nextId() + "";
    }

}
